package logic.handler;

import com.google.protobuf.Message;
import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import logic.IMHandler;
import logic.Worker;
import protobuf.ParseRegistryMap;
import protobuf.Utils;
import protobuf.generate.internal.Internal;
import protobuf.generate.srv2cli.push.Push;

/**
 * Created by tianfei on 2017/4/19.
 */
public class PushHandler extends IMHandler {


    public PushHandler(String userid, long netid, Message msg, ChannelHandlerContext ctx) {
        super(userid, netid, msg, ctx);
    }

    protected void excute(Worker worker) throws Exception {

//        Chat.CPrivateChat msg = (Chat.CPrivateChat) _msg;
//        ByteBuf byteBuf = null;
//
//        //转发给auth
//        byteBuf = Utils.pack2Server(_msg, ParseRegistryMap.CPRIVATECHAT, Internal.Dest.Auth, msg.getDest());
//        LogicServerHandler.getAuthLogicConnection().writeAndFlush(byteBuf);
//
//        //给发消息的人回应
//        Auth.SResponse.Builder sr = Auth.SResponse.newBuilder();
//        sr.setCode(300);
//        sr.setDesc("Server received message successed");
//        byteBuf = Utils.pack2Client(sr.build());
//        _ctx.writeAndFlush(byteBuf);

        Push.SPushMsg msg=(Push.SPushMsg) _msg;
        ByteBuf byteBuf=null;

        //通过gate推送出去
        byteBuf = Utils.pack2Server(msg, ParseRegistryMap.SPUSH, Internal.Dest.Gate);
        _ctx.writeAndFlush(byteBuf);
    }
}
